package LeetCode;

import java.util.HashSet;

public class LC_653_TwoSumIVInputisaBST {

    public static void main(String[] args) {

    }

    public class Solution {
        public boolean findTarget(TreeNode root, int k) {
            return checkTarget(root, k, new HashSet<>());
        }

        boolean checkTarget(TreeNode root, int k, HashSet<Integer> s) {
            if (root == null) return false;
            int cha = k - root.val;
            if (s.contains(cha)) return true;
            s.add(root.val);
            boolean left = checkTarget(root.left, k, s);
            boolean right = checkTarget(root.right, k, s);
            return left || right;
        }
    }

}